const request = require('request')
const axios = require('axios')
const cheerio = require('cheerio')
const fs = require('fs')


async function spiker(){
    let href = []

    let src = await axios.get('https://www.tupianzj.com/meinv/20210104/223044.html')

    let $ = cheerio.load(src.data)

    $('.pages ul li a').each(function(){
        href.push($(this).attr('href'))
    })
    href.shift()
    href.shift()
    href.shift()
    let pic_index = 0
    href.forEach(async (i) => {
        if(i){
            let url = 'https://www.tupianzj.com/meinv/20210104/' + i
            // console.log(url)
            let pic_src = await getPic(url)
            request(pic_src).pipe(
                fs.createWriteStream('./img/'+ pic_index +'.jpg')
            )
            pic_index++

        }
    })
    async function getPic(url){
            let html = await axios.get(url)
            let $ = cheerio.load(html.data)
            let src = $('#bigpicimg').attr('src')
            return src
    }

}
spiker()